import api from '../api/index.js';

const state = {
    LoopImg: [],
    mainTypes: [],
    benefits: [],
    hotTypes: [],
    guessLike: [],
}

const actions = {
    loadHomePage(store) {
        api.multigetData({
            appPlat: "m",
            pids: "136556,106930,51833,51836"
        }).then((data) => {
            if (!data.success) {
                return Promise.reject("错误");
            }
            store.commit("setLoopImg", data.data[136556].list);
            store.commit("setMainTypes", data.data[106930].list);
            store.commit("setBenefits", data.data[51833].list);
            store.commit("setHotTypes", data.data[51836].list);
        }).catch((error) => {

        })
    },

    // 猜你喜欢
    guessLikeData(store) {
        api.guessLikeData({
            pids: "9750",
            sort: "pop",
            cKey: 46
        }).then((data) => {
            if (!data.success) {
                return Promise.reject("错误");
            }
            store.commit("setGuessLike", data.result.wall.docs);
        }).catch((error) => {

        })
    },
}

const mutations = {
    setLoopImg(state, nv) {
        state.LoopImg = nv;
    },
    setMainTypes(state, nv) {
        state.mainTypes = nv;
    },
    setBenefits(state, nv) {
        state.benefits = nv;
    },
    setHotTypes(state, nv) {
        state.hotTypes = nv;
    },
    setGuessLike(state, nv) {
        state.guessLike = nv;
    },
}

export default {
    state,
    actions,
    mutations
}